<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container{
            width: 400px;
            min-height: 400px;
            margin: 100px; 
        }

        .big-img img{
            width: 100%;
        }
        .small-imgs{
            display:flex;
            justify-content: space-between;
        }
        .small-imgs img{
            width: 15%;
            border:solid 2px rgb(226, 217, 217);
            padding: 5px;
        }

        .small-imgs .active{
            border-color: rgb(41, 51, 82)
        }
    </style>
</head>
<body>
    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        //声明组件
        class GoodsImage extends React.Component{

            state = {
                images: [
                    './1.jpg',
                    './2.jpg',
                    './3.jpg',
                    './4.jpg',
                    './5.jpg'
                ],
                cur: 0
            }

            render(){
                return <div className="container">
                    <div className="big-img">
                        <img src={this.state.images[this.state.cur]} alt=""/>
                    </div>
                    <div className="small-imgs">
                        {this.state.images.map((item, index) => {
                            return <img key={index} 
                                className={ index === this.state.cur ? "active" : ""}  
                                src={item}  
                                onMouseOver={this.over(index)}  alt="" />
                        })}
                    </div>
                </div>
            }

            over = (i) => {
                return () => {
                    this.setState({
                        cur: i
                    })
                }
            }
        } 

        //
        ReactDOM.render(<GoodsImage />, document.querySelector("#root"));
        
    </script>
</body>
</html>